package com.qubuyer.utils

import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import android.widget.TextView

/**
 * Author: linwg
 * Time: 2021/2/20 0020
 * Description:
 */
class SpanBuilder {

    var sb = SpannableStringBuilder()

    fun append(cs: CharSequence, fontSize: Int? = null, color: Int? = null): SpanBuilder {
        val start = sb.length
        sb.append(cs)
        val end = sb.length
        fontSize?.let {
            sb.setSpan(AbsoluteSizeSpan(it, false), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        }
        color?.let {
            sb.setSpan(ForegroundColorSpan(it), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        }
        return this
    }

    fun into(view :TextView){
        view.text = sb
    }
}